# -*- coding:utf-8 -*-
from fastapi import FastAPI
from config.app import get_config
from core.sys import register_logger, register_events, register_exception, register_middleware
from fastapi_offline import FastAPIOffline
from route.app import api_router


def create_app() -> FastAPI:
    """
    生成FatAPI对象
    :return:
    """
    settings = get_config()

    app: FastAPI = FastAPIOffline(
        debug=settings.APP_DEBUG,
        docs_url='/docs',
        redoc_url='/redoc',
        description=settings.DESCRIPTION,
        title=settings.PROJECT_NAME,
        version=settings.VERSION
    )

    # 日志设置
    register_logger(app)

    # 事件监听
    register_events(app)

    # 注册路由
    app.include_router(api_router)

    # 注册捕获全局异常
    register_exception(app)

    # 注册中间件
    register_middleware(app, settings)

    # 注册静态文件
    # register_static_file(app)

    return app
